export default {
  components: {
    comTable: () => import("@/household/common/comTable.vue"),
  },
  data() {
    var validateCheckCode = (rule, value, callback) => {
      if (value === "") {
        console.log(value);
        callback(new Error("请输入验证码"));
      } else {
        if (!this.show) {
          let params = {
            telnum: "15202120781",
            code: value,
          };
          this.$ceshiAxios1.post("v1/user/CodeVerify", params).then((res) => {
            console.log(res);
            if (res.data.code == 1) {
              this.markPhone = true;
            } else {
              // this.$message.error(res.data.message+'！！！')
            }
          });
          callback();
        } else {
          this.$message.error("请先发送验证码！！！");
        }
      }
    };
    var validateChecktelNum = (rule, value, callback) => {
      if (value === "") {
        console.log(value);
        callback(new Error("请输入手机号码"));
      } else {
        const telStr =
          /^[1](([3][0-9])|([4][0,1,4-9])|([5][0-3,5-9])|([6][2,5,6,7])|([7][0-8])|([8][0-9])|([9][0-3,5-9]))[0-9]{8}$/;
        if (!telStr.test(value)) {
          callback(new Error("手机号码格式不正确"));
        } else {
          callback();
        }
      }
    };
    return {
      dateTitle: "入职时间",
      markPhone: false,
      name: "返费管理",
      Action: "1",
      markTrue: true,
      form: {
        checkcode: "",
        positionId: "",
        userId: "",
        otherIntegral: "", //业务员奖励
        positionName: "",
        companyName: "",
        entryDateEnd: "",
        entryDateStart: "",
        telnum: "",
        glyTelnum: "15202120781",
        subsidStandards: "",
        remark: "", //明细备注
        upIntegral: "", //上级奖励积分
        entryIntegral: "", //入职奖励积分
        userName: "",
        pageNum: 1,
        pageSize: 10,
      },
      timer: null,
      addFee: false,
      count: 0,
      show: true,
      companyName: "",
      pageSize: 10,
      cur: 1,
      total: 0,
      tdata: [
        {
          companyName: "公司名称",
          distributionStandard: "1111",
          positionName: "岗位名称",
          entryName: "入职用户名称",
          createTime: "入职时间",
          distributionStandard: "补贴标准",
          giveFee: "发放返费",
        },
      ],
      formSeach: {
        companyName: "",
        entryDateStart: "",
        entryDateStart: "",
        userName: "",
      },
      tableData: {
        list: [
          {
            title: "公司名称",
            prop: "companyName",
            isClick: false,
          },
          {
            title: "岗位名称",
            prop: "positionName",
            isClick: false,
          },
          {
            title: "入职用户名称",
            prop: "userName",
            isClick: false,
          },

          {
            title: "入职时间",
            prop: "entryDate",
            isClick: false,
          },
          {
            title: "高补贴标准",
            prop: "subsidStandards",
            isClick: false,
          },
          {
            title: "操作",
            prop: "giveFee",
            isClick: true,
            eventName: "giveFee",
          },
        ],
        noOperation: false, //是否有操作项
        operation: [
          //操作项内容
          // {name:'查看明细',isBtn:false,title:'detailsView'},
        ],
        data: [
          /* {
					projectName: '物险', //项目名称
					createTime: '2020-1-55', //新增时间
					entryNumber: 20, //入职量
					turnover: '20%', //离职率
					suspendTime: '2020-5-12', //中止时间
					projectRemark: 'xxx', //备注
					suspendStatus: '已中止', //操作
					}, */
        ],
      },
      rules: {
        userName: [
          {
            required: true,
            message: "请输入入职人员名称",
            trigger: "blur",
          },
        ],
        telnum: [
          {
            required: true,
            trigger: "blur",
            validator: validateChecktelNum,
          },
        ],
        companyName: [
          {
            required: true,
            message: "请输入公司名称",
            trigger: "blur",
          },
        ],
        entryIntegral: [
          {
            required: true,
            message: "请输入入积分奖励",
            trigger: "blur",
            message: "输入积分数量不能大于4位数",
          },
        ],
        upIntegral: [
          {
            required: true,
            message: "请输入上级奖励积分",
            trigger: "blur",
            message: "输入积分数量不能大于4位数",
          },
        ],
        otherIntegral: [
          {
            required: true,
            message: "请输入业务员奖励",
            trigger: "blur",
            // min: 1,
            // max: 4,
            message: "输入积分数量不能大于4位数",
          },
        ],
        checkcode: [
          {
            required: true,
            validator: validateCheckCode,
            trigger: "blur",
          },
        ],
        remark: [
          {
            required: true,
            message: "请输入备注",
            trigger: "blur",
          },
        ],
        subsidStandards: [
          {
            required: true,
            message: "请输入奖励标准",
            trigger: "blur",
          },
        ],
        positionName: [
          {
            required: true,
            message: "请输入岗位名称",
            trigger: "blur",
          },
        ],
        entryDate: [
          {
            required: true,
            message: "请选择入职时间",
            trigger: "change",
          },
        ],
      },
    };
  },
  created() {
    this.tableData.data = this.tdata;
    this.getTableData(1);
  },
  methods: {
    //提交数据
    subData() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          let params = {};
          if (!this.markPhone) {
            return this.$message.error("验证码错误");
          }
          Object.assign(params, this.form);
          this.$ceshiAxios
            .post("v1/PositionBounty/distributionHighPriceIntegral", params)
            .then((res) => {
              console.log(res);
              if (res.data.code == 1) {
                this.$message.success("操作成功！！！");
                this.addFee = false;
                this.$refs["ruleForm"].resetFields();
                this.Action = "2";
                this.getTableData(2);
              } else {
                this.$message.error(res.data.message);
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleSizeChange(data) {
      this.pageSize = data;
      this.getTableData(this.Action);
    },

    OnplayCurrentChange(data) {
      this.cur = data;
      this.getTableData(this.Action);
    },
    getTableData(index) {
      console.log(index);
      let data = {
        pageNum: this.cur,
        pageSize: this.pageSize,
      };
      let url = "";
      if (index == 1) {
        url = "/v1/PositionBounty/highPricePositonEntry";
      } else if (index == 2) {
        url = "/v1/PositionBounty/returnHighPriceList";
      }
      Object.assign(data, this.formSeach);
      this.$ceshiAxios.post(url, data).then((res) => {
        console.log(res);
        if (res.data.code == 1) {
          if (index == 1) {
            this.tableData = {
              list: [
                {
                  title: "公司名称",
                  prop: "companyName",
                  isClick: false,
                },
                {
                  title: "岗位名称",
                  prop: "positionName",
                  isClick: false,
                },
                {
                  title: "入职用户名称",
                  prop: "userName",
                  isClick: false,
                },

                {
                  title: "入职时间",
                  prop: "entryDate",
                  isClick: false,
                },
                {
                  title: "高补贴标准",
                  prop: "subsidStandards",
                  isClick: false,
                },
                {
                  title: "操作",
                  prop: "giveFee",
                  isClick: true,
                  eventName: "giveFee",
                },
              ],
            };
            this.tableData.data = res.data.data.positionBountyVoList;
            console.log(this.tableData.data);
            this.tableData.data.forEach((item) => {
              item.giveFee = "发放返费";
            });
          } else if (index == 2) {
            this.tableData = {
              list: [
                {
                  title: "公司名称",
                  prop: "companyName",
                  isClick: false,
                },
                {
                  title: "岗位名称",
                  prop: "positionName",
                  isClick: false,
                },
                {
                  title: "入职用户名称",
                  prop: "userName",
                  isClick: false,
                },

                {
                  title: "入职时间",
                  prop: "entryDate",
                  isClick: false,
                },
                {
                  title: "高补贴标准",
                  prop: "subsidStandards",
                  isClick: false,
                },
                {
                  title: "发放时间",
                  prop: "insertDate",
                  isClick: false,
                },
                {
                  title: "操作",
                  prop: "giveFee",
                  isClick: true,
                  eventName: "giveFee",
                },
              ],
            };

            this.tableData.data = res.data.data.highPriceList;
            this.tableData.data.forEach((item) => {
              item.giveFee = "查看返费发放明细";
              item.subsidStandards = item.rewardContent;
            });
          }
          this.total = res.data.data.total;
        }
      });
    },

    handleClose() {
      this.show = true;
      this.addFee = false;
    },
    getCode() {
      let that = this;
      const TIME_COUNT = 60;
      if (!that.timer) {
        that.count = TIME_COUNT;
        that.show = false;
        that.timer = setInterval(() => {
          if (that.count > 0 && that.count <= TIME_COUNT) {
            that.count--;
          } else {
            that.show = true;
            clearInterval(that.timer);
            that.timer = null;
          }
        }, 1000);
      }
      let data = {};
      let codestr = 15202120781 + "/" + "@$%&12#3$#@";
      let md5code = this.$md5(codestr);
      console.log(md5code);
      let params = {
        telnum: 15202120781,
        encryptCode: md5code,
      };
      this.$ceshiAxios1.post("v1/user/sendMsgCode", params).then((res) => {
        console.log(res);
        if (res.data.code == 1) {
          this.$message.success("发送成功");
        } else {
          this.$message.warning(res.data.message);
        }
      });
    },
    OnlineCash(data) {
      this.Action = data;
      this.cur = 1;
      this.getTableData(this.Action);
      if (data == "1") {
        this.dateTitle = "入职时间";
      } else if (data == "2") {
        this.dateTitle = "发放时间";
      }
    },
    onSubmit() {
      this.$ceshiAxios.post("", data).then((res) => {
        this.tableData.data = res.data.data;
      });
    },
    serach() {
      this.getTableData(this.Action);
    },
    giveFee(data) {
      console.log(data);
      this.companyName = data.companyName;
      if (this.Action == "2") {
        this.$ceshiAxios
          .get("/v1/PositionBounty/highPriceInfo?id=" + data.id)
          .then((res) => {
            console.log(res);
            this.form = res.data.data;
            this.form.subsidStandards = res.data.data.rewardContent;
          });
      } else {
        this.form.positionId = data.positionId;
        this.form.userId = data.userId;
        this.form = data;
      }
      this.addFee = true;
    },
  },
};
